<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>果然FruitC</title>
	   <meta name="format-detection" content="telephone=no">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="renderer" content="webkit">
        <meta http-equiv="Cache-Control" content="no-siteapp" />
		<link href="${ctx }/shop/css/amazeui.min.css" rel="stylesheet" type="text/css" />
		<link href="${ctx }/shop/css/style.css" rel="stylesheet" type="text/css" />
		<style>
		.address-cz a {
			text-align:center;
		}
		</style>
	</head>
	<body>
		<header data-am-widget="header" class="am-header am-header-default sq-head ">
			<div class="am-header-left am-header-nav">
					<a href="javascript:go()" class="">
						<i class="am-icon-chevron-left"></i>
					</a>
			</div>
			<h1 class="am-header-title">
  	            <a  class="">管理收货地址</a>
            </h1>
            <div class="am-header-right am-header-nav">
				<a href="${ctx }/editAddress?type=${type}&orderid=${orderid}" class="">
					<i class="am-icon-plus"></i>
				</a>
			</div>
	    </header>
	    <div style="height: 49px;"></div>
	    <ul class="address-list">
	    	<c:if test="${empty list}"><div style="text-align:center;">您暂无收货地址哦</div></c:if>
	    	<c:forEach items="${list }" var="record" varStatus="index">
    		<li onclick="select(this)" id="${record.id }"<c:if test="${record.id ==selectid}"> class="curr"</c:if>>
    			
	    		<p>收货人：${record.name_}&nbsp;&nbsp;${record.mobile_ }</p>
	    		<p class="order-add1">收货地址：${record.addr_ }</p>
	    	    <hr />
	    	    <div class="address-cz">
	    	    	<span class="am-radio am-warning" style="width:33%;margin:0px;float:left;padding:0px;"  onclick = "setDef('${record.id}')">
                       <input type="radio" style="margin:0px;float:none" name = "default"onchange="change(this)" data-am-ucheck  <c:if test="${index.index ==0}">checked</c:if>> 设为默认
                    </span>
                    <a style="width:33%" onclick ="edit('${record.id }')"><img src="${ CTX }/shop/images/bj.png" width="18" />&nbsp;<span >编辑</span></a>
                    <a style="width:33%" onclick="del('${record.id }')" ><span >删除</span></a>
	    	    </div>
	    	</li>
	    	</c:forEach>
	    
	    </ul>
<script src="${ctx }/shop/js/jquery-1.10.2.min.js"></script>
<script src="${ctx }/shop/js/util.js"></script>
<script>
var selectId = "${selectid}";
var originId = "${selectid}";
var defId = "${defId}";

function go(){
	var type = "${type}";
	if("order" == type){
		location.href = "${ctx }/makeOrder?addressid="+selectId;
	}else if("person" == type){
		location.href = "${ctx }/person";
	}else if("modify" == type){
		if(selectId == originId){
			location.href = "${ctx }/orderPage";
		}else{
			hit_box_two('',"",'确认要修改订单收货地址吗?','take_btn','close_btn_all','确定','取消',function(){
				sendReq("${ctx}/modifyAddress",{orderid:"${orderid}",addrid:selectId},function(data){
					location.href = "${ctx }/orderPage";
				})
			},function(){
				
			});
		}
	}
}

function setDef(id){
	if(id == defId) {
		return;
	}
	var e = event || window.event;
	e.preventDefault();
	hit_box_two('',"",'要设置该地址为默认地址吗?','take_btn','close_btn_all','确定','取消',function(){
		sendReq("${ctx}/setAddressDef",{id:id},function(data){
			var input = $("#"+id+" input[type='radio']").prop("checked",true);
			defId = id;
		})
	},function(){
		
	});
}

function select(obj){
	var li = $(obj);
	if(li.hasClass("curr")){
		return;
	}
	$(".curr").removeClass("curr");
	li.addClass("curr");
	selectId = li.attr("id");
}
function change(obj){
	var li = $(obj).parent().parent().parent();
	if(li.hasClass("curr")){
		return;
	}
	$(".curr").removeClass("curr");
	li.addClass("curr");
	selectId = li.attr("id");
}

function del(id){
	hit_box_two('',"",'您确认要删除该地址吗?','take_btn','close_btn_all','确定','取消',function(){
		sendReq("${ctx}/deleteAddress",{id:id},function(data){
			if(data.status){
				$("#"+id).remove();
			}else{
				hit_box_one(data.msg,'','','我知道啦','');
			}
		})
	});
	
}

function edit(id){
	location.href = "${ctx}/editAddress?type=${type}&orderid=${orderid}&id="+id;
}
</script>
<%@include file="../common/jsticket.jsp"%><!--静态包含-->  
	</body>
</html>
